package com.icom.sso.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.xxl.sso.server.core.model.Project;

@Mapper
public interface ProjectMapper {
	@Select("select * from project ")
	@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "project_name", property = "name"),
			@Result(column = "address", property = "address"), @Result(column = "status", property = "status"),
			@Result(column = "logo_path", property = "logoPath") })
	List<Project> findProjects();

	@Insert("insert into project(project_name, address, status, logo_path) values(#{name}, #{address}, #{status}, #{logoPath})")
	int insertProject(Project project);

	@Select("select * from project where id=#{id} ")
	@Results({ @Result(id = true, column = "id", property = "id"), @Result(column = "project_name", property = "name"),
			@Result(column = "address", property = "address"), @Result(column = "status", property = "status"),
			@Result(column = "logo_path", property = "logoPath") })
	Project findProjectById(@Param("id") String id);

	@Update("update project set status = #{status} where id = #{id}")
	int changeStatus(@Param("id") String id, @Param("status") String status);

	@Update({ "<script>", "update project set status = #{status},project_name = #{name},address = #{address}",
			"<when test='logoPath!=null'>", ", logo_path = #{logoPath}", "</when>", "WHERE id=#{id}", "</script>" })
	int saveChangeInfo(Project project);
	
	@Delete("delete from project where id = #{id}")
	int delProjt(String id);
}
